const express = require('express');
const router = express.Router();
const taskController = require('../controllers/task.controller');
const { verifyToken, isSubjectGroupLeader, isTeacher } = require('../middlewares/auth.middleware');

// 自定义中间件：检查用户是否为学科组长或教师
const isSubjectGroupLeaderOrTeacher = (req, res, next) => {
  // 如果roleId为2(学科组长)或3(教师)，则允许访问
  if (req.roleId === 2 || req.roleId === 3) {
    next();
  } else {
    return res.status(403).json({ 
      code: 403,
      message: '需要学科组长或教师权限',
      success: false
    });
  }
};

// 获取教师的批改任务分页数据
router.get('/getReviewAssignmentOfPerson', verifyToken, isSubjectGroupLeaderOrTeacher, taskController.getReviewAssignmentOfPerson);

// 获取批阅任务的试卷详情数据
router.get('/getTaskDetailByOne', verifyToken, isSubjectGroupLeaderOrTeacher, taskController.getTaskDetailByOne);

// 获取批阅任务的主观题详情数据
router.get('/getTaskDetailByTwo', verifyToken, isSubjectGroupLeaderOrTeacher, taskController.getTaskDetailByTwo);

module.exports = router;
